package main

import (
	"flag"
	"fmt"
	"github.com/zeromicro/go-zero/core/conf"
	"github.com/zeromicro/go-zero/core/logx"
	"github.com/zeromicro/go-zero/rest"
	"zero/api/gateway/internal/config"
	"zero/api/gateway/internal/handler"
	"zero/api/gateway/internal/svc"
)

var configFile = flag.String("f", "./api/gateway/etc/gateway-api.yaml", "the config file")

func main() {
	flag.Parse()
	logx.DisableStat()
	var c config.Config
	conf.MustLoad(*configFile, &c)
	//app := fx.New(
	//	fx.Provide(func() *config.Config { return &c }),
	//	fx.Provide(svc.NewServiceContext),
	//	fx.Invoke(func() {
	//		server := rest.MustNewServer(c.RestConf)
	//		defer server.Stop()
	//		ctx := svc.NewServiceContext(c)
	//		handler.RegisterHandlers(server, ctx)
	//		server.Start()
	//	}),
	//)

	//app.Run()
	server := rest.MustNewServer(c.RestConf, rest.WithCors())
	defer server.Stop()

	ctx := svc.NewServiceContext(c)
	handler.RegisterHandlers(server, ctx)

	fmt.Printf("Starting server at %s:%d...\n", c.Host, c.Port)
	server.Start()

}
